package com.apple.learn.poi;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class TestMain {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		File file = new File("F:/workspace/my-learn-pro/target/classes/com/apple/learn/poi/a.xlsx");
		InputStream inputStream = new FileInputStream(file);
		Workbook workbook = new XSSFWorkbook(inputStream);
		processExcel(workbook);
	}

	private static void processExcel(Workbook workbook) {
		Sheet sheet = workbook.getSheetAt(0);
		int rows = sheet.getPhysicalNumberOfRows();
		System.out.println(">> file rows is:"+(rows-1)+" <<");
		Row title = sheet.getRow(0);
		
		for (int row = 1; row < rows; row++) {
			Row rowObj = sheet.getRow(row);
			for (int col = 0; col < 1; col++) {
				String titleName = title.getCell(col).toString();
				Cell cell = rowObj.getCell(col);
				if (titleName.startsWith("time")) {
					System.out.println("==Time:"+cell.getStringCellValue());
				}
			}
		}
		
	}

}
